<?php
namespace app\home\controller;

use app\home\Controller;
use think\View;

class Index 
{
    //用户取杆即开锁操作
    public function index()
    {   
        $view = new View();
        return $view->fetch('index');
    }

    //检测
    public function test(){
    	$lock_number = input('lock_number');
        $lock_info   = db('lock')->where('number',$lock_number)->find(); 

        $data['equipment'] = $lock_info['control_board_number'];
        $data['code']      = $lock_info['lock_number'];
        $data['on']        = 1;
       
        $url = "http://47.93.103.53:9003/Lock_State.asmx/MQTTService";
        // $url    = "http://47.93/WebService1.asmx/MQTTService";
        $result['status'] = httpRequest($url,'POST',$data);

        return json($result);
    }
    
    //开锁
    public function openLock(){
        $lock_number = input('lock_number');
        

        $lock_info = db('lock')->where('number',$lock_number)->find(); 

        $data['equipment'] = $lock_info['control_board_number'];
        $data['code']      = $lock_info['lock_number'];
        $data['on']        = 1;
  
        $url = "http://47.93.103.53:8080/WebService1.asmx/MQTTService";
        // $url    = "http://47.93/WebService1.asmx/MQTTService";
        $data['status'] = httpRequest($url,'POST',$data);
      
        return json($data);
    }

    //关锁 
    public function closeLock(){
        $lock_number = input('lock_number');
        

        $lock_info = db('lock')->where('number',$lock_number)->find(); 

        $data['equipment'] = $lock_info['control_board_number'];
        $data['code']      = $lock_info['lock_number'];
        $data['on']        = 1;
       
        $url = "http://47.93.103.53:9002/WebService1.asmx/MQTTService";
        // $url    = "http://47.93/WebService1.asmx/MQTTService";
        $result['status'] = httpRequest($url,'POST',$data);
      
        return json($result);
    }

    //踢人
    public function endUse(){
        $number = input('number');
        $data['status'] = 0;
        if(isset($number{10})){
            $where['mobile'] = $number;
            if($user_id  = db('user')->where($where)->value('id')){
                if(db('cue_status')->where('user_id',$user_id)->update(['user_id'=>0])){
                    $data['status'] = 1;
                }
            }
           
        }

        return json($data);
    }
  
}
